home *** CD-ROM | disk | FTP | other *** search
/ Multimedia Selection / Multimedia Selection Volume One - CD-ROM / MULTIMEDIA SELECTION____________.ISO / programz / c / clear.arj / FNPTRS.DOC < prev    next >
Encoding:
Text File  |  1989-12-07  |  1.7 KB  |  54 lines

  1. A Fix for Handling Pointers to Functions in the Tree Chart Mode
  2.  
  3. Functions invoked through a pointer (to that function) are difficult for
  4. diagrammers to handle. In the most general case, the actual function called
  5. could be dynamically determined (by the user, say) or could be referenced
  6. by a table offset. Short of compiling the program (or even running it if
  7. the user was asked to enter a function address!) there is no sure way to
  8. determine which functions are called by an arbitrary pointer reference.
  9.  
  10. As a compromise, Clear for C now allows the programmer (who usually knows
  11. which functions are supposed to be called by a pointer reference) to
  12. provide for referencing the functions he/she intends to call.
  13.  
  14. By including a comment of the form :
  15.  
  16. /*# foo() boo() coo() */
  17.  
  18. in the source code, the tree chart/function cross reference will treat these
  19. functions as being called by the function in which this comment appears. 
  20. Be sure to include the # sign!
  21.  
  22. A typical usage might be:
  23.  
  24. /***************************************************************************/
  25. /* fnptrs.c */
  26. /* include str function declarations */
  27. #include <string.h>
  28.  
  29. /* table of function pointers to be selected in program */
  30. int (*fn[2])()=
  31. {
  32. strcmp,
  33. stricmp
  34. };
  35.  
  36. main()
  37. {
  38. int i;
  39.  
  40. while(1)
  41.    {
  42.    printf("Enter 0 for Case Sensitive, 1 for Insensitive, -1 to Quit) ");
  43.    scanf("%d",&i);
  44.    if(i<0 || i>1)
  45.      exit(0);
  46.    printf("fn[%d](\"HI\",\"hi\") returns %d\n",i,fn[i]("HI","hi"));
  47.    /*# strcmp() stricmp() */  /* references these actual functions in tree */
  48.    /* remember to turn 'external functions ON' */
  49.    }
  50. }
  51. /***************************************************************************/
  52.  
  53.  
  54.